﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<title>评议选项</title>
@Html.Partial("LoadPanelPartial")
   @if (false)
   {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
   }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/json2.js",true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script type="text/javascript">

        $(document).ready(function () {
            
            var rs = $("#hdreturnValue").val();
            var hdRuleSorce = $("#hdRuleSorce").val();

            var jsonRs = JSON.parse(rs);
            if (hdRuleSorce == "") {
                for (var i = 0; i < jsonRs.length; i++) {
                    $("#additem").append("<tr class=\"Add\"><td></td><td class=\"tdClass\" align=\"center\"><input type=\"hidden\" value=\"" + jsonRs[i]["FPeerReviewRuleScoreCd"] + "\" style=\"width:60px\" /></td><td class=\"tdClass\" align=\"center\">" + jsonRs[i]["FScoreName"] + "<input type=\"hidden\" value=\"" + jsonRs[i]["FScoreName"] + "\" /></td><td class=\"tdClass\" align=\"center\"><input type=\"text\" value=\"0\" style=\"width:60px\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'')\" onafterpaste=\"this.value=this.value.replace(/[^\\d]/g,'')\" /></td></tr>");
                }
            } else {
                var jsonhdRuleSorce = JSON.parse(hdRuleSorce);
                for (var i = 0; i < jsonRs.length; i++) {
                    var a = false;
                    for (var j = 0; j < jsonhdRuleSorce.length; j++) {
                        if (jsonRs[i]["FPeerReviewRuleScoreCd"] == jsonhdRuleSorce[j]["FPeerReviewRuleScoreCd"]) {
                            $("#additem").append("<tr class=\"Add\"><td><input type=\"hidden\" value=\"" + jsonhdRuleSorce[i]["FPeerReviewRuleCd"] + "\" /></td><td class=\"tdClass\" align=\"center\"><input type=\"hidden\" value=\"" + jsonhdRuleSorce[i]["FPeerReviewRuleScoreCd"] + "\"/></td><td class=\"tdClass\" align=\"center\">" + jsonhdRuleSorce[i]["FScoreName"] + "<input type=\"hidden\" value=\"" + jsonhdRuleSorce[i]["FScoreName"] + "\" style=\"width:60px\" /></td><td class=\"tdClass\" align=\"center\"><input type=\"text\" value=\"" + jsonhdRuleSorce[i]["FScore"] + "\" style=\"width:60px\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'')\" onafterpaste=\"this.value=this.value.replace(/[^\\d]/g,'')\" /></td></tr>");
                            a = true;
                            break;
                        }
                    }
                    if (!a) {
                        $("#additem").append("<tr class=\"Add\"><td><input type=\"hidden\" value=\"0\" /></td><td class=\"tdClass\" align=\"center\"><input type=\"hidden\" value=\"" + jsonRs[i]["FPeerReviewRuleScoreCd"] + "\" /></td><td class=\"tdClass\" align=\"center\">" + jsonRs[i]["FScoreName"] + "<input type=\"hidden\" value=\"" + jsonRs[i]["FScoreName"] + "\" style=\"width:60px\" /></td><td class=\"tdClass\" align=\"center\"><input type=\"text\" value=\"0\" style=\"width:60px\" onkeyup=\"this.value=this.value.replace(/[^\\d]/g,'')\" onafterpaste=\"this.value=this.value.replace(/[^\\d]/g,'')\" /></td></tr>");
                    }
                }
            }



            var detailHtml = '{"FPeerReviewRuleCd":"","FPeerReviewRuleScoreCd":"","FScoreName":"","FScore":0}';
            $("#btnOK").bind("click", function () {
                var List = JSON.parse("[]");
                var ISNULL = true;
                $('.Add').each(function () {
                    var detailModel = JSON.parse(detailHtml);

                    detailModel.FPeerReviewRuleCd = $.trim($(this).find('td').eq(0).find(':hidden').val());
                    if ($.trim($(this).find('td').eq(1).find(':hidden').val()) != "") {
                        detailModel.FPeerReviewRuleScoreCd = $.trim($(this).find('td').eq(1).find(':hidden').val());
                    } else {
                        alert("选项编号不能为空！");
                        ISNULL = false;
                        return false;
                    }
                    if ($.trim($(this).find('td').eq(2).find(':hidden').val()) != "") {
                        detailModel.FScoreName = $.trim($(this).find('td').eq(2).find(':hidden').val());
                    } else {
                        alert("选项名称不能为空！");
                        ISNULL = false;
                        return false;
                    }
                    if ($.trim($(this).find('td').eq(3).find(':text').val()) != "") {
                        detailModel.FScore = $.trim($(this).find('td').eq(3).find(':text').val());
                    } else {
                        detailModel.FScore = 0;
                    }
                    List.push(detailModel);
                });

                if (!ISNULL) {
                    return;
                }
                var ListStr = "";
                if (List.length > 0) {

                    ListStr = JSON.stringify(List);
                }

                window.returnValue = ListStr;
                window.close();
            });
            $("#btnCancel").bind("click", function () {
                window.close();
            });

        });
     </script>
</head>
<body>
    <div>
        <table width="100%" class="tableForm" border="0">       
             <tr height="25">             
                <td colspan="4" class="tdClass">
                    <table width="100%" class="tableForm" id="additem">                     
                        <tr height="25">
                        <td></<td>
                        <td class="tdClass" style =" text-align:center"></td>                          
                            <td class="tdClass" style =" text-align:center">@Html.DevExpress().Label(settings => { settings.Text = "选项"; settings.Properties.Style.Font.Bold = true; }).GetHtml()</td>
                            <td class="tdClass" style =" text-align:center">@Html.DevExpress().Label(settings => { settings.Text = "分值"; settings.Properties.Style.Font.Bold = true; }).GetHtml()</td>
                        </tr>
                    </table>
                </td>
             </tr>  
        </table>    
    </div>
    <div style="padding: 0px; background: #efefef; width: 100%; font-size: 12px; text-align: center;">
        <table align="center">
            <tr>
                <td>
                    @Html.DevExpress().Button(settings =>
               {
                   settings.Name = "btnOK";
                   settings.Text = "确定";

                   settings.Images.Image.Url = Url.Content("~/Content/ControlImages/ok.png");
                   
               }).GetHtml()
                </td>
                <td>
                    @Html.DevExpress().Button(settings =>
               {
                   settings.Name = "btnCancel";
                   settings.Text = "取消";

                   settings.Images.Image.Url = Url.Content("~/Content/ControlImages/no.png");
                   settings.CausesValidation = false;
                   
               }).GetHtml()
                </td>
            </tr>
        </table>
        @Html.Hidden("hdreturnValue", ViewData["returnValue"])
        @Html.Hidden("hdRuleSorce", ViewData["hdRuleSorce"])
    </div>
</body>
</html>
